SUBROUTINE CHECK_UNIT0(nunit)
implicit none

! Input variables
integer(4), intent(in):: nunit

! Local variables
logical unit_opened

inquire (unit=nunit,opened=unit_opened)

if (unit_opened) then
  print*, 'The unit ', nunit, 'is attempted &
 & to be connected to a file, while already connected: STOP'
  STOP
endif

END SUBROUTINE CHECK_UNIT0
